import { ref, onMounted } from "vue";
import { appletList } from "../../../../api/common";

interface IOptions {
  label: string;
  value: string;
}
const appletDataOptions = [{ label: "全部小程序", value: "" }];
export default function useAppletData() {
  const appletData = ref<Array<IOptions>>(appletDataOptions);
  const getAppletList = async () => {
    let data = {
      page: 1,
      pageSize: 999999
    };
    let res = await appletList(data);
    if (res.code === 0) {
      let list = res.data.list.map((item: any) => {
        const obj = {
          label: item.name,
          value: item.code
        };
        return obj;
      });
      appletData.value = appletDataOptions.concat(list);
      appletData?.value[0].value;
    }
  };

  onMounted(getAppletList);

  return {
    appletData
  };
}
